package com.caimiao.miao.library.database;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.caimiao.miao.MiaoApplication;
import com.caimiao.miao.library.database.table.DeviceTable;
import com.caimiao.miao.library.database.table.TicketInTable;
import com.caimiao.miao.library.database.table.TicketOutTable;

public class SQLiteDBHelper extends SQLiteOpenHelper {
    private static final String DB_NAME = "miao.db";
    private static final int DB_VERSION = 1;
    public static volatile SQLiteDBHelper instance;

    public static SQLiteDBHelper getInstance() {
        if (instance == null) {
            synchronized (SQLiteDBHelper.class) {
                if (instance == null)
                    instance = new SQLiteDBHelper();
            }
        }
        return instance;
    }

    public SQLiteDBHelper() {
        super(MiaoApplication.getContext(), DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TicketOutTable.CREATE_SQL);
        db.execSQL(TicketInTable.CREATE_SQL);
        db.execSQL(DeviceTable.CREATE_SQL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //版本迭代：1、2、3、4...
        switch (oldVersion) {
            case 1:
            case 2:
            case 3:
            case 4:
                break;
        }
    }

}
